Use @nestjs/oauth2-server which wraps the oauth2-server library. Implement the OAuth2 model interface to provide data persistence for clients, tokens, and authorization codes. Register grants (authorization_code, client_credentials, refresh_token) in the module configuration.
getClient() — validate client credentials and return the registered OAuth2 client.
saveAuthorizationCode() / getAuthorizationCode() — persist and retrieve short-lived authorization codes.
saveToken() / getAccessToken() — persist and retrieve access and refresh tokens.
verifyScope() — confirm the requested scopes are included in the granted token scopes.
Always hash client secrets before storing — treat them like passwords.